name: C++ CI

on: [push]

jobs:

  short_fuzzing:
    runs-on: ubuntu-latest
    steps:
    - name: Build fuzzers
      id: build
      uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
      with:
        oss-fuzz-project-name: 'uwebsockets'
        language: c++
    - name: Run fuzzers
      uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
      with:
        oss-fuzz-project-name: 'uwebsockets'
        language: c++
        fuzz-seconds: 600
    - name: Upload crash
      uses: actions/upload-artifact@v4
      if: failure() && steps.build.outcome == 'success'
      with:
        name: artifacts
        path: ./out/artifacts

  build_windows:
    runs-on: windows-latest
    steps:
      - name: Clone source
        run: git clone --recursive https://github.com/uNetworking/uWebSockets.git
      - name: Install libuv
        run: |
          vcpkg install libuv:x64-windows
          cp C:\vcpkg\installed\x64-windows\bin\uv.dll uWebSockets\uv.dll
      - uses: ilammy/msvc-dev-cmd@v1
      - name: Build examples
        run: |
          cd uWebSockets
          $Env:WITH_ZLIB='0'; $ENV:WITH_LTO='0'; $Env:CC='clang';
          $ENV:CFLAGS='-I C:\vcpkg\installed\x64-windows\include';
          $ENV:LDFLAGS='-L C:\vcpkg\installed\x64-windows\lib';
          $ENV:CXX='clang++'; $ENV:EXEC_SUFFIX='.exe'; $ENV:WITH_LIBUV='1'; nmake
          ls
      - name: Run unit tests
        run: $Env:CC='clang'; $Env:CXX='clang++'; make -C uWebSockets/tests
      - name: Run smoke test
        run: |
          cd uWebSockets
          iwr https://deno.land/x/install/install.ps1 -useb | iex
          Start-Process -NoNewWindow .\Crc32
          sleep 1
          deno run --allow-net tests\smoke.mjs
          Stop-Process -Name Crc32

  build_linux:

    runs-on: ubuntu-latest
    
    steps:
    - name: Clone source
      run: git clone --recursive https://github.com/uNetworking/uWebSockets.git
    - name: Build source
      run: make -C uWebSockets
    - name: List binaries
      run: ls uWebSockets
    - name: Install Deno
      run: curl -fsSL https://deno.land/x/install/install.sh | sh
    - name: Run smoke test
      run: make -C uWebSockets/tests smoke
    - name: Run unit tests
      run: make -C uWebSockets/tests
      
  build_osx:

    runs-on: macos-latest
    
    steps:
    - name: Clone source
      run: git clone --recursive https://github.com/uNetworking/uWebSockets.git
    - name: Build source
      run: make -C uWebSockets
    - name: List binaries
      run: ls uWebSockets
    - name: Install Deno
      run: curl -fsSL https://deno.land/x/install/install.sh | sh
    - name: Run smoke test
      run: make -C uWebSockets/tests smoke
    - name: Run unit tests
      run: make -C uWebSockets/tests
